home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-13 | 2.9 KB | 93 lines | [TEXT/AxoC] |
- LocalLanguage Fortran
- c -------------------------------------------------------
- c The following functions demonstrate various aspects of
- c AxoCalculator's Fortran programming language.
- c
- c • To load all the demo functions, choose "Select All"
- c under the "Edit" menu, then press "enter".
- c
- c • To run a function, type its name followed
- c by any parameters, then press "enter".
- c
- c • After the functions are loaded, this file does
- c not need to remain open in order to use them.
- c
- c • Here are some examples of how to use the functions
- c (remove the "c" at the start of each line before testing) .
- c
- c BoxVolume (10,15,20)
- c Factorial (10)
- c RecursiveFact (10)
- c SameBirthDateProb(25)
- c --------------------------------------------------
-
- c ---------------- RectArea ------------------------
- c This function calculates the area of a rectangle
- c given its height and width.
- c -------------------------------------------------
- function RectArea (height, width)
- RectArea = height * width
- end
-
- c ---------------- BoxVolume ----------------------
- c This function calculates the volume of a box
- c given its height, width and depth. It calls the
- c function RectArea to get the area of the bottom of
- c the box, then multiplies the result by the box depth.
- c -------------------------------------------------
- function BoxVolume (height, width, depth)
- BoxVolume = RectArea (height, width) * depth
- end
-
- c ---------------- Factorial ---------------------
- c This function calculates the factorial of a number.
- c ----------------------------------------------
- function Factorial (number)
- integer i
- real f
- c ..............................................................................................................
- f = 1
- do i = 1, number
- f = f * i
- enddo
- Factorial = f
- end
-
- c ---------------- RecursiveFact -------------------
- c This function also calculates the factorial of a number,
- c but it uses a recursive algorithm. This approach is
- c inefficient, but demonstrates recursion.
- c -----------------------------------------------}
- function RecursiveFact (number)
- if number > 1 then
- RecursiveFact = number * RecursiveFact (number - 1)
- else
- RecursiveFact = 1
- end
-
-
- c ---------------- SameBirthDateProb ------------------
- c This function calculates the probability that two or more
- c people in a group have the same birth date, given the
- c number of people in the group. It works by calculating
- c 1 - the probability that everyone in the group has a
- c different birth date.
- c ----------------------------------------------------
- function SameBirthDateProb (numberOfPeople)
- if (numberOfPeople < 2) then
- DiffBirthDateProb = 1
- else
- if (numberOfPeople > 365) then
- DiffBirthDateProb = 0
- else
- DiffBirthDateProb = 1
- Do i = 2, numberOfPeople
- DiffBirthDateProb = DiffBirthDateProb * (366-i) / 365
- enddo
- endif
- endif
- SameBirthDateProb = 1 - DiffBirthDateProb
- end
-
-
-